The @Optional() decorator marks a constructor dependency as optional. If the provider is not registered in the DI container, NestJS injects undefined instead of throwing an error. Useful when building libraries or optional integrations where a provider may or may not be configured by the consumer.
Building reusable library modules where consumers may not configure all providers.
Feature flags — optionally inject a service only when a feature module is loaded.
Fallback behavior — use a default implementation when the provider is absent.
Always use TypeScript optional typing (?) alongside @Optional() for type safety.